package com.hspedu.tankgame03;

public class Shot implements Runnable{
    int x;
    int y; //子弹坐标
    int dircet; //子弹方向
    int speed = 5; //子弹速度
    boolean isLive = true; //子弹是否存活

    public Shot(int x, int y, int dircet) {
        this.x = x;
        this.y = y;
        this.dircet = dircet;
    }

    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            switch (dircet) { //根据方向改变坐标
                case 0: //上
                    y -= speed;
                    break;
                case 1: //右
                    x += speed;
                    break;
                case 2: //下
                    y += speed;
                    break;
                case 3: //左
                    x -= speed;
                    break;
            }
            System.out.println(x + " " + y);
            //子弹到面板边界时，销毁
            if (!(x>=0 && x<=1000 && y>=0 && y<=750)){
                isLive = false;
                break;
            }

        }
    }
}
